package com.custom.jdbc.executor.convert;

import com.custom.jdbc.executebody.SqlExecutorBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author XiaoBai
 * @since 2024/3/28 0028 22:53
 */
public interface TypeMappedHandler {

    Logger log = LoggerFactory.getLogger(TypeMappedHandler.class);


    /**
     * 获取目标对象
     */
    <T> T getTargetObject(SqlExecutorBody executorBody, Class<T> mappedType, ResultSet rs) throws Exception;

    /**
     * 获取目标值
     *
     * @param colIndex 取当前行的第几列值(从1开始)
     */
    <T> T getTargetObject(Class<T> mappedType, ResultSet rs, int colIndex) throws Exception;

    /**
     * 设置修改的参数值
     */
    void setUpdateParam(SqlExecutorBody executorBody, PreparedStatement statement) throws Exception;

    /**
     * 设置查询的参数值
     */
    void setQueryParam(SqlExecutorBody executorBody, PreparedStatement statement) throws Exception;

    /**
     * 将rs中的结果写入集合并返回
     *
     * @param rs       jdbc结果集对象
     * @param colIndex 取当前行的第几列值(从1开始)
     */
    <T> List<T> getTargetList(SqlExecutorBody executorBody, Class<T> mappedType, ResultSet rs, int colIndex) throws Exception;

    /**
     * 将rs中的结果写入数组并返回
     *
     * @param rs       jdbc结果集对象
     * @param colIndex 取当前行的第几列值(从1开始)
     * @param count    数组总长度
     */
    <T> T[] getTargetArrays(SqlExecutorBody executorBody, Class<T> mappedType, ResultSet rs, int colIndex, int count) throws Exception;

    /**
     * 获取map
     */
    <T> Map<String, T> getTargetMap(SqlExecutorBody executorBody, Class<T> mappedType, ResultSet rs) throws Exception;

}
